--
-- PostgreSQL database dump
--

-- Started on 2011-06-19 18:11:33

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- TOC entry 1924 (class 1262 OID 369492)
-- Name: adrs; Type: DATABASE; Schema: -; Owner: postgres
--

CREATE DATABASE adrs WITH TEMPLATE = template0 ENCODING = 'UTF8';


ALTER DATABASE adrs OWNER TO postgres;

\connect adrs

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- TOC entry 7 (class 2615 OID 369493)
-- Name: adrs; Type: SCHEMA; Schema: -; Owner: postgres
--

CREATE SCHEMA adrs;


ALTER SCHEMA adrs OWNER TO postgres;

--
-- TOC entry 348 (class 2612 OID 369496)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres
--

-- CREATE PROCEDURAL LANGUAGE plpgsql;


ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO postgres;

SET search_path = adrs, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 1520 (class 1259 OID 369497)
-- Dependencies: 7
-- Name: contato; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE contato (
    id bigint NOT NULL,
    numero character varying(32) NOT NULL,
    usuario_id bigint NOT NULL
);


ALTER TABLE adrs.contato OWNER TO postgres;

--
-- TOC entry 1521 (class 1259 OID 369500)
-- Dependencies: 1813 1814 7
-- Name: detalhes_produtor; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE detalhes_produtor (
    id_adrs bigint NOT NULL,
    id_produtor bigint NOT NULL,
    ativo boolean DEFAULT true NOT NULL,
    conjuge character varying(100),
    conjuge_cpf character varying(11),
    pai character varying(100),
    mae character varying(100),
    latitude double precision,
    longitude double precision,
    dap character varying(50),
    estado_civil integer DEFAULT 0 NOT NULL
);


ALTER TABLE adrs.detalhes_produtor OWNER TO postgres;

--
-- TOC entry 1523 (class 1259 OID 369507)
-- Dependencies: 7
-- Name: doenca_sanitario; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE doenca_sanitario (
    id_sanitario bigint NOT NULL,
    id_doenca bigint NOT NULL,
    quantidade integer
);


ALTER TABLE adrs.doenca_sanitario OWNER TO postgres;

--
-- TOC entry 1524 (class 1259 OID 369510)
-- Dependencies: 7
-- Name: endereco; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE endereco (
    id bigint NOT NULL,
    localidade character varying(100) NOT NULL,
    distancia_sede bigint NOT NULL,
    municipio_id bigint NOT NULL
);


ALTER TABLE adrs.endereco OWNER TO postgres;

--
-- TOC entry 1525 (class 1259 OID 369513)
-- Dependencies: 7
-- Name: estado; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE estado (
    id bigint NOT NULL,
    nome character varying(32) NOT NULL,
    uf character varying(2) NOT NULL
);


ALTER TABLE adrs.estado OWNER TO postgres;

--
-- TOC entry 1526 (class 1259 OID 369516)
-- Dependencies: 7
-- Name: faixa_etaria; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE faixa_etaria (
    id bigint NOT NULL,
    inicio integer NOT NULL,
    fim integer NOT NULL
);


ALTER TABLE adrs.faixa_etaria OWNER TO postgres;

--
-- TOC entry 1527 (class 1259 OID 369519)
-- Dependencies: 7
-- Name: municipio; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE municipio (
    id bigint NOT NULL,
    nome character varying(64) NOT NULL,
    estado_id bigint NOT NULL
);


ALTER TABLE adrs.municipio OWNER TO postgres;

--
-- TOC entry 1528 (class 1259 OID 369522)
-- Dependencies: 7
-- Name: papel; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE papel (
    id bigint NOT NULL,
    nome character varying(20) NOT NULL
);


ALTER TABLE adrs.papel OWNER TO postgres;

--
-- TOC entry 1529 (class 1259 OID 369525)
-- Dependencies: 7
-- Name: perfil; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE perfil (
    id bigint NOT NULL,
    usuario_id bigint NOT NULL,
    papel_id bigint NOT NULL,
    data_criacao date NOT NULL,
    ativo boolean NOT NULL,
    data_exclusao date,
    justificativa_exclusao text
);


ALTER TABLE adrs.perfil OWNER TO postgres;

--
-- TOC entry 1530 (class 1259 OID 369528)
-- Dependencies: 7
-- Name: prazo; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE prazo (
    id bigint NOT NULL,
    inicio date,
    fim date,
    sanitario boolean,
    quantitativo boolean,
    qualitativo boolean
);


ALTER TABLE adrs.prazo OWNER TO postgres;

--
-- TOC entry 1531 (class 1259 OID 369531)
-- Dependencies: 7
-- Name: prazo_adrs; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE prazo_adrs (
    id_prazo bigint NOT NULL,
    id_adrs bigint NOT NULL
);


ALTER TABLE adrs.prazo_adrs OWNER TO postgres;

--
-- TOC entry 1532 (class 1259 OID 369534)
-- Dependencies: 7
-- Name: qt_descarte; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE qt_descarte (
    id bigint NOT NULL,
    mes integer NOT NULL,
    sexo character varying(1) NOT NULL,
    qtd integer NOT NULL,
    tipo_animal_id bigint NOT NULL,
    quantitativo_id bigint NOT NULL
);


ALTER TABLE adrs.qt_descarte OWNER TO postgres;

--
-- TOC entry 1533 (class 1259 OID 369537)
-- Dependencies: 1815 1816 1817 1818 1819 1820 1821 7
-- Name: qt_movimentacao; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE qt_movimentacao (
    id bigint NOT NULL,
    comprados integer DEFAULT 0 NOT NULL,
    vendidos integer DEFAULT 0 NOT NULL,
    nascidos integer DEFAULT 0 NOT NULL,
    mortos integer DEFAULT 0 NOT NULL,
    roubados integer DEFAULT 0 NOT NULL,
    qtd_anterior integer DEFAULT 0 NOT NULL,
    qtd_atual integer DEFAULT 0 NOT NULL,
    tipo_animal_id bigint NOT NULL,
    quantitativo_id bigint NOT NULL
);


ALTER TABLE adrs.qt_movimentacao OWNER TO postgres;

--
-- TOC entry 1534 (class 1259 OID 369547)
-- Dependencies: 7
-- Name: qt_rebanho; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE qt_rebanho (
    id bigint NOT NULL,
    qtd integer NOT NULL,
    sexo character varying(1) NOT NULL,
    tipo_animal_id bigint NOT NULL,
    quantitativo_id bigint NOT NULL,
    faixa_etaria_id bigint NOT NULL
);


ALTER TABLE adrs.qt_rebanho OWNER TO postgres;

--
-- TOC entry 1535 (class 1259 OID 369550)
-- Dependencies: 7
-- Name: questionario_qualitativo_tec; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE questionario_qualitativo_tec (
    id bigint NOT NULL,
    data date NOT NULL,
    visita_id bigint NOT NULL
);


ALTER TABLE adrs.questionario_qualitativo_tec OWNER TO postgres;

--
-- TOC entry 1536 (class 1259 OID 369553)
-- Dependencies: 7
-- Name: questionario_quantitativo_qt; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE questionario_quantitativo_qt (
    id bigint NOT NULL,
    data date NOT NULL,
    visita_id bigint NOT NULL,
    relato text
);


ALTER TABLE adrs.questionario_quantitativo_qt OWNER TO postgres;

--
-- TOC entry 1537 (class 1259 OID 369559)
-- Dependencies: 7
-- Name: questionario_sanitario_qs; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE questionario_sanitario_qs (
    id bigint NOT NULL,
    data date,
    visita_id bigint,
    relato text
);


ALTER TABLE adrs.questionario_sanitario_qs OWNER TO postgres;

--
-- TOC entry 1538 (class 1259 OID 369565)
-- Dependencies: 7
-- Name: tec_avaliacao_geral; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE tec_avaliacao_geral (
    zootecnica integer,
    id_animal integer,
    mort_nascidos double precision,
    mort_adultos double precision,
    descarte_orientado integer,
    div_propriedade integer,
    reserva_agua integer,
    prop_eletrificada integer,
    maquinario integer,
    qualitativo_id bigint NOT NULL
);


ALTER TABLE adrs.tec_avaliacao_geral OWNER TO postgres;

--
-- TOC entry 1539 (class 1259 OID 369568)
-- Dependencies: 7
-- Name: tec_avaliacao_instalacao; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE tec_avaliacao_instalacao (
    aprisco integer,
    brete integer,
    curral_pega integer,
    instalacoes_reprodutor integer,
    rampa_ordenha integer,
    qualitativo_id bigint NOT NULL
);


ALTER TABLE adrs.tec_avaliacao_instalacao OWNER TO postgres;

--
-- TOC entry 1540 (class 1259 OID 369571)
-- Dependencies: 7
-- Name: tec_avaliacao_nutricional; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE tec_avaliacao_nutricional (
    sal_mineral integer,
    suplemento_alimentar integer,
    ensilagem integer,
    fenacao integer,
    proteinas integer,
    qualitativo_id bigint NOT NULL
);


ALTER TABLE adrs.tec_avaliacao_nutricional OWNER TO postgres;

--
-- TOC entry 1541 (class 1259 OID 369574)
-- Dependencies: 7
-- Name: tec_avaliacao_organizacional; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE tec_avaliacao_organizacional (
    vendas_planejadas integer,
    associado integer,
    qualitativo_id bigint NOT NULL
);


ALTER TABLE adrs.tec_avaliacao_organizacional OWNER TO postgres;

--
-- TOC entry 1542 (class 1259 OID 369577)
-- Dependencies: 7
-- Name: tec_avaliacao_reprodutiva; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE tec_avaliacao_reprodutiva (
    estacao_monta integer,
    castracao integer,
    separacao_sexo integer,
    rufiao integer,
    qualitativo_id bigint NOT NULL
);


ALTER TABLE adrs.tec_avaliacao_reprodutiva OWNER TO postgres;

--
-- TOC entry 1543 (class 1259 OID 369580)
-- Dependencies: 7
-- Name: tec_avaliacao_sanitaria; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE tec_avaliacao_sanitaria (
    vermifugacao integer,
    exames_opg integer,
    calendario_vacinacao integer,
    higiene_instalacoes integer,
    pediluvio integer,
    corte_curaumbigo integer,
    farmacia integer,
    limpeza_desinfecao integer,
    esterqueira integer,
    manejo_casqueamento integer,
    qualitativo_id bigint NOT NULL
);


ALTER TABLE adrs.tec_avaliacao_sanitaria OWNER TO postgres;

--
-- TOC entry 1544 (class 1259 OID 369583)
-- Dependencies: 7
-- Name: tipo_animal; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE tipo_animal (
    id bigint NOT NULL,
    tipo character varying(32) NOT NULL
);


ALTER TABLE adrs.tipo_animal OWNER TO postgres;

--
-- TOC entry 1522 (class 1259 OID 369504)
-- Dependencies: 7
-- Name: tipo_doenca; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE tipo_doenca (
    id bigint NOT NULL,
    nome character varying(30)
);


ALTER TABLE adrs.tipo_doenca OWNER TO postgres;

--
-- TOC entry 1545 (class 1259 OID 369586)
-- Dependencies: 7
-- Name: usuario; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE usuario (
    id bigint NOT NULL,
    nome character varying(100) NOT NULL,
    login character varying(100) NOT NULL,
    senha character varying NOT NULL,
    cpf character varying(11) NOT NULL,
    apelido character varying(100) NOT NULL,
    endereco_id bigint NOT NULL,
    email character varying(100),
    rg character varying(50)
);


ALTER TABLE adrs.usuario OWNER TO postgres;

--
-- TOC entry 1546 (class 1259 OID 369592)
-- Dependencies: 7
-- Name: visita; Type: TABLE; Schema: adrs; Owner: postgres; Tablespace: 
--

CREATE TABLE visita (
    id bigint NOT NULL,
    produtor_id bigint,
    adrs_id bigint,
    data date NOT NULL
);


ALTER TABLE adrs.visita OWNER TO postgres;

--
-- TOC entry 1823 (class 2606 OID 369596)
-- Dependencies: 1520 1520
-- Name: PK_CONTATO; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY contato
    ADD CONSTRAINT "PK_CONTATO" PRIMARY KEY (id);


--
-- TOC entry 1855 (class 2606 OID 369598)
-- Dependencies: 1532 1532
-- Name: PK_DESCARTE; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY qt_descarte
    ADD CONSTRAINT "PK_DESCARTE" PRIMARY KEY (id);


--
-- TOC entry 1837 (class 2606 OID 369600)
-- Dependencies: 1525 1525
-- Name: PK_ESTADO; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY estado
    ADD CONSTRAINT "PK_ESTADO" PRIMARY KEY (id);


--
-- TOC entry 1839 (class 2606 OID 369602)
-- Dependencies: 1526 1526
-- Name: PK_FAIXA_ETARIA; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY faixa_etaria
    ADD CONSTRAINT "PK_FAIXA_ETARIA" PRIMARY KEY (id);


--
-- TOC entry 1857 (class 2606 OID 369604)
-- Dependencies: 1533 1533
-- Name: PK_MOVIMENTACAO; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY qt_movimentacao
    ADD CONSTRAINT "PK_MOVIMENTACAO" PRIMARY KEY (id);


--
-- TOC entry 1841 (class 2606 OID 369606)
-- Dependencies: 1527 1527
-- Name: PK_MUNICIPIO; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY municipio
    ADD CONSTRAINT "PK_MUNICIPIO" PRIMARY KEY (id);


--
-- TOC entry 1861 (class 2606 OID 369608)
-- Dependencies: 1535 1535
-- Name: PK_QUALITATIVO; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY questionario_qualitativo_tec
    ADD CONSTRAINT "PK_QUALITATIVO" PRIMARY KEY (id);


--
-- TOC entry 1863 (class 2606 OID 369610)
-- Dependencies: 1536 1536
-- Name: PK_QUANTITATIVO; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY questionario_quantitativo_qt
    ADD CONSTRAINT "PK_QUANTITATIVO" PRIMARY KEY (id);


--
-- TOC entry 1859 (class 2606 OID 369612)
-- Dependencies: 1534 1534
-- Name: PK_REBANHO; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY qt_rebanho
    ADD CONSTRAINT "PK_REBANHO" PRIMARY KEY (id);


--
-- TOC entry 1879 (class 2606 OID 369614)
-- Dependencies: 1544 1544
-- Name: PK_TIPO_ANIMAL; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tipo_animal
    ADD CONSTRAINT "PK_TIPO_ANIMAL" PRIMARY KEY (id);


--
-- TOC entry 1893 (class 2606 OID 369616)
-- Dependencies: 1546 1546
-- Name: PK_VISITA; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY visita
    ADD CONSTRAINT "PK_VISITA" PRIMARY KEY (id);


--
-- TOC entry 1867 (class 2606 OID 369618)
-- Dependencies: 1538 1538
-- Name: ava_ger_pk; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tec_avaliacao_geral
    ADD CONSTRAINT ava_ger_pk PRIMARY KEY (qualitativo_id);


--
-- TOC entry 1869 (class 2606 OID 369620)
-- Dependencies: 1539 1539
-- Name: ava_instalacao; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tec_avaliacao_instalacao
    ADD CONSTRAINT ava_instalacao PRIMARY KEY (qualitativo_id);


--
-- TOC entry 1871 (class 2606 OID 369622)
-- Dependencies: 1540 1540
-- Name: ava_nutricional; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tec_avaliacao_nutricional
    ADD CONSTRAINT ava_nutricional PRIMARY KEY (qualitativo_id);


--
-- TOC entry 1873 (class 2606 OID 369624)
-- Dependencies: 1541 1541
-- Name: ava_organizacional_pk; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tec_avaliacao_organizacional
    ADD CONSTRAINT ava_organizacional_pk PRIMARY KEY (qualitativo_id);


--
-- TOC entry 1875 (class 2606 OID 369626)
-- Dependencies: 1542 1542
-- Name: ava_reprodutiva_pk; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tec_avaliacao_reprodutiva
    ADD CONSTRAINT ava_reprodutiva_pk PRIMARY KEY (qualitativo_id);


--
-- TOC entry 1877 (class 2606 OID 369628)
-- Dependencies: 1543 1543
-- Name: ava_sanitaria; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tec_avaliacao_sanitaria
    ADD CONSTRAINT ava_sanitaria PRIMARY KEY (qualitativo_id);


--
-- TOC entry 1825 (class 2606 OID 369630)
-- Dependencies: 1521 1521 1521
-- Name: det_produtor_pk; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY detalhes_produtor
    ADD CONSTRAINT det_produtor_pk PRIMARY KEY (id_adrs, id_produtor);


--
-- TOC entry 1833 (class 2606 OID 369632)
-- Dependencies: 1523 1523 1523
-- Name: doen_san_pk; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY doenca_sanitario
    ADD CONSTRAINT doen_san_pk PRIMARY KEY (id_sanitario, id_doenca);


--
-- TOC entry 1831 (class 2606 OID 369634)
-- Dependencies: 1522 1522
-- Name: doenca_pk; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tipo_doenca
    ADD CONSTRAINT doenca_pk PRIMARY KEY (id);


--
-- TOC entry 1835 (class 2606 OID 369636)
-- Dependencies: 1524 1524
-- Name: pk_endereco; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY endereco
    ADD CONSTRAINT pk_endereco PRIMARY KEY (id);


--
-- TOC entry 1843 (class 2606 OID 369638)
-- Dependencies: 1528 1528
-- Name: pk_papel; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY papel
    ADD CONSTRAINT pk_papel PRIMARY KEY (id);


--
-- TOC entry 1847 (class 2606 OID 369640)
-- Dependencies: 1529 1529
-- Name: pk_perfil; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY perfil
    ADD CONSTRAINT pk_perfil PRIMARY KEY (id);


--
-- TOC entry 1883 (class 2606 OID 369642)
-- Dependencies: 1545 1545
-- Name: pk_usuario; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT pk_usuario PRIMARY KEY (id);


--
-- TOC entry 1853 (class 2606 OID 369644)
-- Dependencies: 1531 1531 1531
-- Name: prazo_adrs_fk; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY prazo_adrs
    ADD CONSTRAINT prazo_adrs_fk PRIMARY KEY (id_prazo, id_adrs);


--
-- TOC entry 1851 (class 2606 OID 369646)
-- Dependencies: 1530 1530
-- Name: prazo_pk; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY prazo
    ADD CONSTRAINT prazo_pk PRIMARY KEY (id);


--
-- TOC entry 1865 (class 2606 OID 369648)
-- Dependencies: 1537 1537
-- Name: quest_sanitario; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY questionario_sanitario_qs
    ADD CONSTRAINT quest_sanitario PRIMARY KEY (id);


--
-- TOC entry 1827 (class 2606 OID 582638)
-- Dependencies: 1521 1521
-- Name: unicidade_conjuge_cpf; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY detalhes_produtor
    ADD CONSTRAINT unicidade_conjuge_cpf UNIQUE (conjuge_cpf);


--
-- TOC entry 1885 (class 2606 OID 476200)
-- Dependencies: 1545 1545
-- Name: unicidade_cpf; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT unicidade_cpf UNIQUE (cpf);


--
-- TOC entry 1829 (class 2606 OID 582640)
-- Dependencies: 1521 1521
-- Name: unicidade_dap; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY detalhes_produtor
    ADD CONSTRAINT unicidade_dap UNIQUE (dap);


--
-- TOC entry 1887 (class 2606 OID 582646)
-- Dependencies: 1545 1545
-- Name: unicidade_email; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT unicidade_email UNIQUE (email);


--
-- TOC entry 1889 (class 2606 OID 476198)
-- Dependencies: 1545 1545
-- Name: unicidade_login; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT unicidade_login UNIQUE (login);


--
-- TOC entry 1845 (class 2606 OID 582642)
-- Dependencies: 1528 1528
-- Name: unicidade_papel; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY papel
    ADD CONSTRAINT unicidade_papel UNIQUE (nome);


--
-- TOC entry 1891 (class 2606 OID 582648)
-- Dependencies: 1545 1545
-- Name: unicidade_rg; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT unicidade_rg UNIQUE (rg);


--
-- TOC entry 1881 (class 2606 OID 582644)
-- Dependencies: 1544 1544
-- Name: unicidade_tipo_animal; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY tipo_animal
    ADD CONSTRAINT unicidade_tipo_animal UNIQUE (tipo);


--
-- TOC entry 1849 (class 2606 OID 369650)
-- Dependencies: 1529 1529 1529
-- Name: uniq_usuario_papel; Type: CONSTRAINT; Schema: adrs; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY perfil
    ADD CONSTRAINT uniq_usuario_papel UNIQUE (usuario_id, papel_id);


--
-- TOC entry 1905 (class 2606 OID 369651)
-- Dependencies: 1536 1532 1862
-- Name: FK_DESCARTE_QUANTITATIVO; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY qt_descarte
    ADD CONSTRAINT "FK_DESCARTE_QUANTITATIVO" FOREIGN KEY (quantitativo_id) REFERENCES questionario_quantitativo_qt(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1906 (class 2606 OID 369656)
-- Dependencies: 1878 1532 1544
-- Name: FK_DESCARTE_TIPO_ANIMAL; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY qt_descarte
    ADD CONSTRAINT "FK_DESCARTE_TIPO_ANIMAL" FOREIGN KEY (tipo_animal_id) REFERENCES tipo_animal(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1907 (class 2606 OID 369661)
-- Dependencies: 1533 1862 1536
-- Name: FK_MOVIMENTACAO_QUANTITATIVO; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY qt_movimentacao
    ADD CONSTRAINT "FK_MOVIMENTACAO_QUANTITATIVO" FOREIGN KEY (quantitativo_id) REFERENCES questionario_quantitativo_qt(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1908 (class 2606 OID 369666)
-- Dependencies: 1544 1533 1878
-- Name: FK_MOVIMENTACAO_TIPO_ANIMAL; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY qt_movimentacao
    ADD CONSTRAINT "FK_MOVIMENTACAO_TIPO_ANIMAL" FOREIGN KEY (tipo_animal_id) REFERENCES tipo_animal(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1900 (class 2606 OID 369671)
-- Dependencies: 1836 1527 1525
-- Name: FK_MUNICIPIO_ESTADO; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY municipio
    ADD CONSTRAINT "FK_MUNICIPIO_ESTADO" FOREIGN KEY (estado_id) REFERENCES estado(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1909 (class 2606 OID 369676)
-- Dependencies: 1534 1838 1526
-- Name: FK_REBANHO_FAIXA_ETARIA; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY qt_rebanho
    ADD CONSTRAINT "FK_REBANHO_FAIXA_ETARIA" FOREIGN KEY (faixa_etaria_id) REFERENCES faixa_etaria(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1910 (class 2606 OID 369681)
-- Dependencies: 1862 1534 1536
-- Name: FK_REBANHO_QUANTITATIVO; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY qt_rebanho
    ADD CONSTRAINT "FK_REBANHO_QUANTITATIVO" FOREIGN KEY (quantitativo_id) REFERENCES questionario_quantitativo_qt(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1911 (class 2606 OID 369686)
-- Dependencies: 1544 1534 1878
-- Name: FK_REBANHO_TIPO_ANIMAL; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY qt_rebanho
    ADD CONSTRAINT "FK_REBANHO_TIPO_ANIMAL" FOREIGN KEY (tipo_animal_id) REFERENCES tipo_animal(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1912 (class 2606 OID 369691)
-- Dependencies: 1892 1546 1535
-- Name: FK_VISITA; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY questionario_qualitativo_tec
    ADD CONSTRAINT "FK_VISITA" FOREIGN KEY (visita_id) REFERENCES visita(id);


--
-- TOC entry 1913 (class 2606 OID 369696)
-- Dependencies: 1546 1536 1892
-- Name: FK_VISITA_ID; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY questionario_quantitativo_qt
    ADD CONSTRAINT "FK_VISITA_ID" FOREIGN KEY (visita_id) REFERENCES visita(id);


--
-- TOC entry 1903 (class 2606 OID 369701)
-- Dependencies: 1531 1529 1846
-- Name: adrs_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY prazo_adrs
    ADD CONSTRAINT adrs_fk FOREIGN KEY (id_adrs) REFERENCES perfil(id);


--
-- TOC entry 1915 (class 2606 OID 369706)
-- Dependencies: 1538 1535 1860
-- Name: ava_ger_qualitativo_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY tec_avaliacao_geral
    ADD CONSTRAINT ava_ger_qualitativo_fk FOREIGN KEY (qualitativo_id) REFERENCES questionario_qualitativo_tec(id);


--
-- TOC entry 1916 (class 2606 OID 369711)
-- Dependencies: 1535 1860 1539
-- Name: ava_ins_qualitativo_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY tec_avaliacao_instalacao
    ADD CONSTRAINT ava_ins_qualitativo_fk FOREIGN KEY (qualitativo_id) REFERENCES questionario_qualitativo_tec(id);


--
-- TOC entry 1917 (class 2606 OID 369716)
-- Dependencies: 1860 1540 1535
-- Name: ava_nut_qualitativo_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY tec_avaliacao_nutricional
    ADD CONSTRAINT ava_nut_qualitativo_fk FOREIGN KEY (qualitativo_id) REFERENCES questionario_qualitativo_tec(id);


--
-- TOC entry 1918 (class 2606 OID 369721)
-- Dependencies: 1541 1860 1535
-- Name: ava_org_qualitativo_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY tec_avaliacao_organizacional
    ADD CONSTRAINT ava_org_qualitativo_fk FOREIGN KEY (qualitativo_id) REFERENCES questionario_qualitativo_tec(id);


--
-- TOC entry 1919 (class 2606 OID 369726)
-- Dependencies: 1860 1542 1535
-- Name: ava_rep_qualitativo_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY tec_avaliacao_reprodutiva
    ADD CONSTRAINT ava_rep_qualitativo_fk FOREIGN KEY (qualitativo_id) REFERENCES questionario_qualitativo_tec(id);


--
-- TOC entry 1920 (class 2606 OID 369731)
-- Dependencies: 1543 1860 1535
-- Name: ava_san_qualitativo_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY tec_avaliacao_sanitaria
    ADD CONSTRAINT ava_san_qualitativo_fk FOREIGN KEY (qualitativo_id) REFERENCES questionario_qualitativo_tec(id);


--
-- TOC entry 1897 (class 2606 OID 369736)
-- Dependencies: 1523 1522 1830
-- Name: doenca_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY doenca_sanitario
    ADD CONSTRAINT doenca_fk FOREIGN KEY (id_doenca) REFERENCES tipo_doenca(id);


--
-- TOC entry 1894 (class 2606 OID 369741)
-- Dependencies: 1882 1520 1545
-- Name: fk_contato_usuario; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY contato
    ADD CONSTRAINT fk_contato_usuario FOREIGN KEY (usuario_id) REFERENCES usuario(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1899 (class 2606 OID 369746)
-- Dependencies: 1524 1840 1527
-- Name: fk_endereco_municipio; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY endereco
    ADD CONSTRAINT fk_endereco_municipio FOREIGN KEY (municipio_id) REFERENCES municipio(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1901 (class 2606 OID 369751)
-- Dependencies: 1842 1529 1528
-- Name: fk_perfil_papel; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY perfil
    ADD CONSTRAINT fk_perfil_papel FOREIGN KEY (papel_id) REFERENCES papel(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1902 (class 2606 OID 369756)
-- Dependencies: 1545 1882 1529
-- Name: fk_perfil_usuario; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY perfil
    ADD CONSTRAINT fk_perfil_usuario FOREIGN KEY (usuario_id) REFERENCES usuario(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1921 (class 2606 OID 369761)
-- Dependencies: 1524 1545 1834
-- Name: fk_usuario_endereco; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT fk_usuario_endereco FOREIGN KEY (endereco_id) REFERENCES endereco(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 1895 (class 2606 OID 369766)
-- Dependencies: 1521 1846 1529
-- Name: id_adrs_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY detalhes_produtor
    ADD CONSTRAINT id_adrs_fk FOREIGN KEY (id_adrs) REFERENCES perfil(id);


--
-- TOC entry 1896 (class 2606 OID 369771)
-- Dependencies: 1521 1846 1529
-- Name: id_prod_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY detalhes_produtor
    ADD CONSTRAINT id_prod_fk FOREIGN KEY (id_produtor) REFERENCES perfil(id);


--
-- TOC entry 1904 (class 2606 OID 369776)
-- Dependencies: 1850 1530 1531
-- Name: prazo_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY prazo_adrs
    ADD CONSTRAINT prazo_fk FOREIGN KEY (id_prazo) REFERENCES prazo(id);


--
-- TOC entry 1898 (class 2606 OID 369781)
-- Dependencies: 1537 1864 1523
-- Name: sanitario_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY doenca_sanitario
    ADD CONSTRAINT sanitario_fk FOREIGN KEY (id_sanitario) REFERENCES questionario_sanitario_qs(id);


--
-- TOC entry 1914 (class 2606 OID 369786)
-- Dependencies: 1537 1892 1546
-- Name: visita_fk; Type: FK CONSTRAINT; Schema: adrs; Owner: postgres
--

ALTER TABLE ONLY questionario_sanitario_qs
    ADD CONSTRAINT visita_fk FOREIGN KEY (visita_id) REFERENCES visita(id);


--
-- TOC entry 1926 (class 0 OID 0)
-- Dependencies: 6
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


-- Completed on 2011-06-19 18:12:22

--
-- PostgreSQL database dump complete
--

